﻿(function ($) {

    /* Navbar Functions*/
    var navbar_js = function () {
        $('.dropdown-mega-menu > a, .nav-menu > li:has( > ul) > a').append("<span class=\"indicator\"><i class=\"fa fa-angle-down\"></i></span>");
        $('.nav-menu > li ul > li:has( > ul) > a').append("<span class=\"indicator\"><i class=\"fa fa-angle-right\"></i></span>");
        $(".dropdown-mega-menu, .nav-menu li:has( > ul)").on('mouseenter', function () {
            if ($(window).width() > 992) {
                $(this).children("ul, .mega-menu").fadeIn(100);
            }
        });
        $(".dropdown-mega-menu, .nav-menu li:has( > ul)").on('mouseleave', function () {
            if ($(window).width() > 992) {
                $(this).children("ul, .mega-menu").fadeOut(100);
            }
        });
        $(".dropdown-mega-menu > a, .nav-menu li:has( > ul) > a").on('click', function (e) {
            if ($(window).width() <= 992) {
                $(this).parent().addClass("active-mobile").children("ul, .mega-menu").slideToggle(150, function () {

                });
                $(this).parent().siblings().removeClass("active-mobile").children("ul, .mega-menu").slideUp(150);
            }
            e.preventDefault();
        });
        $(".nav-toggle").on('click', function (e) {
            var toggleId = $(this).data("toggle");
            $(toggleId).slideToggle(150);
            e.preventDefault();
        });
    };

    /*Back to Top*/
    var backtop = function () {
        $("#backtotop").hide();

        $(window).scroll(function () {
            if ($(window).scrollTop() > 100) {
                $("#backtotop").fadeIn(400);
            }
            else {
                $("#backtotop").fadeOut(400);
            }
        });

        $("#backtotop").click(function () {
            $('body,html').animate({ scrollTop: 0 }, 400);
            return false;
        });
    };
    
    /*get current year*/
    var current_year = function () {
        var Url = "../Common/GetYear.ashx";
        $.ajax({
            type: "GET",
            url: Url,
            cache: false,
            success: function (returnYear) {
                $("#cyear").html(returnYear);
            }
        });
    };

    /*get shopping cart product number*/
    var cart_amount = function () {
        var url = "../Common/AjaxQty.ashx";
        $.ajax({
            type: "GET",
            url: url,
            cache: false,
            success: function (html) {
                $(".cart-total").html(html);
            }
        });
    };


    /* ================================
       When document is ready, do
    ================================= */

    $(document).ready(function () {
        navbar_js();
        backtop();
        current_year();
        cart_amount();

    });

})(jQuery);



function ViewCart() {
    window.location.href = "../MyCart/MyCart.aspx?flag=view"
}


//<!--Begin Comm100 Live Chat Code-->

var Comm100API = Comm100API || new Object;
Comm100API.chat_buttons = Comm100API.chat_buttons || [];
var comm100_chatButton = new Object;
comm100_chatButton.code_plan = 22;
comm100_chatButton.div_id = 'comm100';
Comm100API.chat_buttons.push(comm100_chatButton);
Comm100API.site_id = 159521;
Comm100API.main_code_plan = 22;

var comm100_lc = document.createElement('script');
comm100_lc.type = 'text/javascript';
comm100_lc.async = true;
comm100_lc.src = 'https://chatserver.comm100.com/livechat.ashx?siteId=' + Comm100API.site_id;
var comm100_s = document.getElementsByTagName('script')[0];
comm100_s.parentNode.insertBefore(comm100_lc, comm100_s);

setTimeout(function () {
    if (!Comm100API.loaded) {
        var lc = document.createElement('script');
        lc.type = 'text/javascript';
        lc.async = true;
        lc.src = 'https://hostedmax.comm100.com/chatserver/livechat.ashx?siteId=' + Comm100API.site_id;
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(lc, s);
    }
}, 5000)

//<!--End Comm100 Live Chat Code-->